<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Sign up|Blog</title>

    <script type="text/javascript" src="../public/js/jquery-2.1.1.min.js"></script>
    <script src="../public/js/jquery-easyui/jquery.easyui.min.js"></script>
    <link rel="stylesheet" href="../public/js/jquery-easyui/themes/default/easyui.css" type="text/css"></link>
    <link rel="stylesheet" href="../public/js/jquery-easyui/themes/icon.css" type="text/css"></link>

    <link href="../public/css/register.css" rel="stylesheet" type="text/css"/>

    <script type="text/javascript">
    	$(function(){
			$("button").click(function(){
			if($("#signup_email").val()==""||$("#signup_password").val()==""||$("#signup_confirm_password").val()==""||$("#signup_username").val()=="")
			{
				$.messager.alert('警告','邮箱、用户名、密码不能为空！');
				
			}
			else
			{
				if($("#signup_password").val()!=$("#signup_confirm_password").val())
				{
						$.messager.alert('警告','输入的两次密码不一致!');
						$("#signup_password").val("");
						$("#signup_confirm_password").val("");
				}
				else
				{
                    var email = $("#signup_email").val();
                    var username =$("#signup_username").val();
                    var password = $("#signup_password").val();

                    /**
                     * ajax向接口传参，并处理
                     */
                    $.ajax({
                        async: false,
                        type: "POST",
                        url:"/users/add",
                        data:{
                            email: email,
                            username: username,
                            password: password,

                        },
                        dataType: "json",
                        success: function (result) { //result为返回结果
                            if (result.code==0){
                                alert("注册成功");
                                window.location.href="login";
                            }else if (result.code=1025){
                                alert("您注册的邮箱已使用！");
                            }else{
                                alert("内部错误,请尽快联系管理员！");
                            }

                        },
                        error: function () {
                        }
                    })
				}
			}
		});
	});
    </script>
</head>
<body>
    <div id="login_bg" class ="login_bg" style="background-image:url(../public/images/blog_bg.jpg);"></div>
    <div class="login_header">
    	<span></span>
    </div>
    
    <div class="container">
    	<div class="form_header">
        	<h1 id="logo">Blog.</h1>
			<h2 id="subheading">To follow me,just sign up</h2>
        </div>
        	<div class="signup_forms">
            	<div id="signup_forms_container" class="signup_forms_container">
                    	<form class="signup_form_form" id="sign_form" method="post" action="userRegister.jsp">
                        	<div class="signup_account" id="signup_account">
                            	<div class="form_user">	
        							<input type="text" name="email" placeholder="Email" id="signup_email"/>
                                </div>
                                <div class="form_username">
           							<input type="text" name="username" placeholder="Username" id="signup_username"/>
        						</div>
                                <div class="form_password">
           							<input type="password" name="password" placeholder="Password" id="signup_password"/>
        						</div>
        						<div class="form_confirm_password">
           							<input type="password"  placeholder="Confirm the password" id="signup_confirm_password"/>
        						</div>
                            </div>
                             <div>
                				<button type="button" id="signup_forms_submit" ><span style="font-size:16px;"><strong>Sign up</strong></span></button>
           	   				 </div>
                        </form>
                </div>
    </div>
   </div>

    <div class="footer">
    	<div class="footer_signup_link">
        	<a class="signup_link" href="login.html">Log in</a>
            <a href="https://www.baidu.com" target="_blank" class="link unnamed_1">Contact</a>
            <a href="#" target="_blank" class="link unnamed_2">About</a>
        </div>
        <div class="design_show">
        	<div class="designer_info">
            	<a href="#">Designed by Class 2 Software 11 <strong>Ray</strong></a>
                <a href="#" target="_blank" class="face"><img id="face" src="../public/images/face.jpg" alt="designed by RayZhang"/></a>
            </div>
        </div>
    </div>
</body>
</html>
